<?php
include ('include/function.php');
valid_user();
include ('include/header.php');

if (isset($_GET['contest_id']))
    $contest_id = $_GET['contest_id'];
else {
    echo 'contest does not exist';
    exit;
}
?>

<title>Submit</title>
    <div id="headline">
        <div class="wrapper">
            <h2>Submit</h2>
        </div>
    </div>    

    <script language="javascript">
        function validateFormData() {
            var source = document.getElementById("source");
            if (source.value.length == 0) {
                alert("Please paster your source before submit");
                return false;
            }
            else if(source.value.length > 200000){
                alert("Source is too long");
                return false;
            }
            return true;
        }
    </script>

<?php
    $contest_title = get_contest_title($contest_id);
    $problem = get_problem_info($contest_id);
?>

<div id="pagebody">
	<div class="wrapper">
    <form id="form1" action="submit.do" method=post onsubmit="return validateFormData()">
	    <input type="hidden" name="contest_id" value="<?php echo $contest_id;?>"/>
        <table><tbody>
            <tr>
                <th width=80></th>
                <th colspan=2><h2>Contest - <?php echo $contest_title; ?><h2></th>
                <th width=80></th>
            </tr>
            <tr>
                <td></td>
                <td align="right"><b>Problem:&nbsp;</b></td>
                <td align="left">
                    <select size=1 name="as_problem">
                    <?php
                        for ($i = 0; $i < count($problem); $i++)
                        echo "<option value=\"{$problem[$i]['as_problem']}\">{$problem[$i]['as_problem']}</option>";
                    ?>
                    </select>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td align="right"><b>Language:&nbsp;</b></td>
                <td align="left">
                    <select size=1 name="language">
                        <option value="C">GCC</option>
                        <option value="C++" selected>G++</option>
                        <option value="Java">Java</option>
                        <option value="Pascal">Pascal</option>
                    </select>
                </td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td align="right"><b>Source:&nbsp;</b></td>
                <td align="left">
                    <textarea style="width:700px; height:500px; wrap: soft" id="source" name="source"></textarea>
                </td>
                <td></td>
            </tr>
            <tr>
                <td colSpan=4 align=center>
                    <input class="button-secondary" type="submit" value="Submit" name="submit" />
                    <input class="button-secondary" type="reset" value="Reset" />
                </td>
            </tr>
        </tbody></table>
    </form>
    </div>
</div>
<?php
    include ('include/footer.php');
?>

